<template>
  <div class="item-one" ref="itemOne">
    <div class="title">
      <span>分账订单查询</span>
      <div>
        <el-button type="primary" :disabled="exxxx" @click="SplitOrderExcel()"
          ><i class="el-icon-download"></i>导出</el-button
        >
      </div>
    </div>
    <div class="container">
      <div class="screeningBox">
        <div class="leftBox">
          <div class="leftitem">
            <el-date-picker
              v-model="date"
              type="datetimerange"
              :picker-options="pickerOptions"
              value-format="yyyy-MM-dd HH:mm:ss"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :clearable="false"
              :default-time="['00:00:00', '23:59:59']"
            >
            </el-date-picker>
            <el-select
              v-if="userinfo.rolesId != 5 && userinfo.rolesId != 6"
              class="width30"
              v-model="channelType"
              placeholder="通道类型"
            >
              <el-option keys="1" label="全部" value=""></el-option>
              <el-option
                v-for="(item, index) in channelslist"
                :key="index"
                :label="item.options"
                :value="item.code"
              ></el-option>
            </el-select>
          </div>
          <div
            class="leftitem"
            v-if="
              userinfo.rolesId != 5 &&
              userinfo.rolesId != 6 &&
              userinfo.rolesId != 4
            "
          >
            <el-form ref="conditions" :model="conditions">
              <el-autocomplete
                v-if="
                  userinfo.rolesId == 1 ||
                  userinfo.rolesId == 8 ||
                  userinfo.rolesId == 9
                "
                class="service"
                v-model.trim="conditions.agent1"
                :fetch-suggestions="querySearch"
                placeholder="请选择一级服务商"
                @select="serviceid"
              ></el-autocomplete>
              <el-autocomplete
                v-if="
                  userinfo.rolesId == 1 ||
                  userinfo.rolesId == 8 ||
                  userinfo.rolesId == 2 ||
                  userinfo.rolesId == 9
                "
                class="service"
                v-model.trim="conditions.agent2"
                :fetch-suggestions="querySearch2"
                placeholder="请选择二级服务商"
                @select="serviceid2"
              ></el-autocomplete>
              <el-autocomplete
                v-if="
                  userinfo.rolesId != 4 &&
                  userinfo.rolesId != 5 &&
                  userinfo.rolesId != 6
                "
                class="service"
                v-model.trim="conditions.BDname"
                :fetch-suggestions="BDname"
                placeholder="业务经理"
                @select="BDid"
              ></el-autocomplete>
            </el-form>
          </div>
          <div class="leftitem">
           
          </div>

          <div class="leftitem">
            <div class="block">
              <el-form label-width="80px">
                <el-select v-model="payStatusCode" placeholder="订单状态">
                  <el-option
                    v-for="item in ordeStatus"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
                <el-select v-model="splitStatus" placeholder="分账状态">
                  <el-option
                    v-for="item in CardBindingStatus"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form>
            </div>
          </div>

          
        </div>
        <div class="rightBox">
          <div class="rightitem">
            <el-input
              class="width60"
              v-model.trim="tradeKeyWords"
              placeholder="交易商户号/交易商户名称"
            ></el-input>
            <el-input
              class="width60"
              v-model.trim="shopKeyWords"
              placeholder="关键字"
            ></el-input>
          
          </div>
          <div class="rightitem">
            <el-input
              class="width60"
              v-model.trim="shopCode"
              placeholder="门店号"
            ></el-input>
            <el-input
              class="width60"
              v-model.trim="terminalNo"
              placeholder="终端号"
            ></el-input>
          </div>
          <div class="rightitem">
            <el-input
              class="merchants width60"
              v-model.trim="tradeNo"
              placeholder="交易订单号"
            ></el-input>
           
          </div>
          <div class="rightitem">
            <el-button icon="el-icon-search" type="primary" @click="soso"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" type="primary" @click="reset"
              >重置</el-button
            >
          </div>
        </div>
      </div>
      <div class="stitle">合计:</div>
      <div class="statistical">
        <div class="statisticalitem">
          <div>总交易金额</div>
          <div>
            <span class="red">{{
              indentinfo.totalFee ? indentinfo.totalFee : 0.0
            }}</span>
            元
          </div>
        </div>
        <div class="statisticalitem">
          <div>总实收金额</div>
          <div>
            <span class="red">{{
              indentinfo.balance ? indentinfo.balance : 0.0
            }}</span>
            元
          </div>
        </div>
        <div class="statisticalitem">
          <div>总手续费</div>
          <div>
            <span class="red">{{ indentinfo.fee ? indentinfo.fee : 0.0 }}</span>
            元
          </div>
        </div>
        <div class="statisticalitem">
          <div>总结算金额</div>
          <div>
            <span class="red">{{
              indentinfo.reportFee ? indentinfo.reportFee : 0.0
            }}</span>
            元
          </div>
        </div>
        <div class="statisticalitem">
          <div>总交易笔数</div>
          <div>
            <span class="red">{{
              indentinfo.tradeCount ? indentinfo.tradeCount : 0
            }}</span>
            笔
          </div>
        </div>
        <div class="statisticalitem">
          <div>总分账金额</div>
          <div>
            <span class="red">{{
              indentinfo.splitTotalFee ? indentinfo.splitTotalFee : 0.0
            }}</span>
            元
          </div>
        </div>
        <div class="statisticalitem">
          <div>总分账笔数</div>
          <div>
            <span class="red">{{
              indentinfo.splitCount ? indentinfo.splitCount : 0
            }}</span>
            笔
          </div>
        </div>
      </div>
      <div class="tableBox">
        <el-table
          ref="multipleTable"
          :data="merchantarr"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
          stripe
          :header-cell-style="tableHeaderColor"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column
            align="center"
            type="index"
            label="序号"
          ></el-table-column>
          <el-table-column
            label="交易时间?交易订单号"
            align="center"
            :render-header="renderheader"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.settleTime }}</div>
              <div>{{ scope.row.tradeNo }}
                <i
                  class="el-icon-copy-document iconmove"
                  @click="copyChannelTradeNoFunc(scope.row.tradeNo)"
                  v-clipboard:copy="copyoutTradeNo"
                  v-clipboard:success="onCopy"
                  v-clipboard:error="onError"
                />
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="订单金额(元)?订单状态"
            align="center"
            :render-header="renderheader"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.trsTotalFee }}</div>
              <div>
                <span
                  v-if="scope.row.payStatusCode == '支付成功'"
                  class="green"
                  >{{ scope.row.payStatusCode }}</span
                >
                <span
                  v-else-if="scope.row.payStatusCode == '退款成功'"
                  class="green"
                  >{{ scope.row.payStatusCode }}</span
                >
                <span
                  v-else-if="scope.row.payStatusCode == '支付中'"
                  class="orange"
                  >{{ scope.row.payStatusCode }}</span
                >
                <span
                  v-else-if="scope.row.payStatusCode == '支付失败'"
                  class="hui"
                  >{{ scope.row.payStatusCode }}</span
                >
                <span
                  v-else-if="scope.row.payStatusCode == '退款失败'"
                  class="hui"
                  >{{ scope.row.payStatusCode }}</span
                >
                <span v-else>
                  {{ scope.row.payStatusCode }}
                </span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="通道名称?交易手续费"
            align="center"
            :render-header="renderheader"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.channelName }}</div>
              <div>{{ scope.row.trsTradeFee }}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="订单类型?支付方式"
            align="center"
            :render-header="renderheader"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.tradeType }}</div>
              <div>{{ scope.row.payMode }}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="商户号?商户名"
            align="center"
            :render-header="renderheader"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.tradeMerNo }}</div>
              <div>{{ scope.row.tradeMerName }}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="分账时间?渠道订单号"
            align="center"
            :render-header="renderheader"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.createTime }}</div>
              <div>{{ scope.row.channelSplitNo }}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="分账金额?分账状态"
            align="center"
            :render-header="renderheader"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.trsTotalFee }}</div>
              <div>
                <span
                  v-if="scope.row.trsSplitStatus == '已分账'"
                  class="green"
                  >{{ scope.row.trsSplitStatus }}</span
                >
                <span
                  v-else-if="scope.row.trsSplitStatus == '分账中'"
                  class="orange"
                  >{{ scope.row.trsSplitStatus }}</span
                >
                <span
                  v-else-if="scope.row.trsSplitStatus == '分账失败'"
                  class="hui"
                  >{{ scope.row.trsSplitStatus }}</span
                >
                <span
                  v-else-if="scope.row.trsSplitStatus == '支付失败'"
                  class="hui"
                  >{{ scope.row.trsSplitStatus }}</span
                >
                <span
                  v-else-if="scope.row.trsSplitStatus == '未分账'"
                  class="hui"
                  >{{ scope.row.trsSplitStatus }}</span
                >
                <span v-else>
                  {{ scope.row.trsSplitStatus }}
                </span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="分账手续费"
            align="center"
            :render-header="renderheader"
          >
            <template slot-scope="scope">
              <!-- <div>{{ scope.row.channelName }}</div> -->
              <div>{{ scope.row.trsSplitFee }}</div>
            </template>
          </el-table-column>
          <el-table-column
          v-if="merchantarr[0]?merchantarr[0].tradeMerNo == 'Y52310240005':''" 
            label="档口号?租户名称"
            align="center"
            :render-header="renderheader"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.shopNo }}</div>
              <div>{{ scope.row.shopName }}</div>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            width="120"
            align="center"
          >
            <template slot-scope="scope">
              <el-button
                type="text"
                size="small"
                @click="JumpDetails(scope.row.id)"
                >详情</el-button
              >
              <el-button
                type="text"
                size="small"
                @click="InitiateAccountSplitting(scope.row)"
                :valu="scope.row.id"
                v-if="scope.row.trsSplitStatus == '未分账'"
                >分账</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination">
          <el-pagination
            background
            @current-change="handleCurrentChange"
            @size-change="sizechange"
            :page-size="10"
            :current-page.sync="cur_page"
            layout="total, sizes, prev, pager, next, jumper"
            :total="combined"
          ></el-pagination>
        </div>
      </div>
      <br />
      <br />
      <!-- 分账 -->
      <el-dialog
        v-dialogDrag
        title="分账"
        :visible.sync="spFormVisible"
        width="40%"
        :close-on-click-modal="false"
      >
        <div class="widthFrom">
          <div class="WithdrawalStyle">
            <span class="WithdrawalWordStyle">是否确认分账？</span>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="spFormVisible = false">取消</el-button>
          <el-button type="primary" @click="InitiateAccountOk">确定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import {
  getservice,
  getBD,
  merchantlist,
  shop,
  dictionarylist,
  APILedgerOrderQuery,
  APILedgerOrderStatisticsQuery,
  APISplitOrderExcel,
  APIDivideAccounts,
} from "@/api/api";
import { setSessionStorage, registeredEvents } from "@/utils";

export default {
  name: "item-one",
  data: function () {
    return {
      copyoutTradeNo:'',

      spFormVisible: false, //分账弹窗
      tradeNo: "",
      shopNo: "",
      shopKeyWords: "",
      shopName: "",
      tradeKeyWords: "",
      splitFeeMch: "",
      shopCode: "",
      terminalNo: "",
      splitStatus: "",
      CardBindingStatus: [
        {
          value: "0",
          label: "初始化",
        },
        {
          value: "1",
          label: "成功",
        },
        {
          value: "2",
          label: "处理中",
        },
        {
          value: "3",
          label: "失败",
        },
      ],
      payStatusCode: undefined,
      ordeStatus: [
        {
          value: "1",
          label: "支付成功",
        },
        {
          value: "2",
          label: "支付失败",
        },
        {
          value: "3",
          label: "支付中",
        },
        {
          value: "5",
          label: "退款成功",
        },
        {
          value: "6",
          label: "退款失败",
        },
      ],
      orderVisible: false,
      orderForm: {},
      formLabelWidth: "85px",
      labelPosition: "left",
      myrolesId: "", //权限
      refundBtnFlag: false, // 退款按钮控制
      tableData: [],
      cur_page: 1,
      cur_size: 10,
      multipleSelection: [],
      visible: false,
      loading: true,
      exxxx: false,
      sosobtn: false,
      servicearr1: [],
      servicearr2: [],
      BDarr: [],
      merchantarr: [],
      merchantarrlist: [],
      restaurants: [],
      combined: 10,
      pageCount: "",
      merchantsinfo: "",
      shopname: "",
      shopid: "",
      date: "",
      userinfo: "",
      statistic: "123",
      indentinfo: {},
      newobj: {},
      shoplists: [],
      merchantslists: [],
      channelslist: [],
      password: {
        psd: "",
        money: "",
      },
      channelType: "",

      conditions: {
        totalFeenum: "",
        serviceid: "",
        payStatusCode: "",
        BDname: "",
        bdId: "",
        merchantId: "",
      },
      payStatusCodearr: [
        { value: "全部", id: "" },
        { value: "支付成功", id: 1 },
        { value: "支付失败", id: 2 },
        { value: "支付中", id: 3 },
        { value: "已撤销", id: 4 },
        { value: "退款成功", id: 5 },
        { value: "退款失败", id: 6 },
        { value: "冲正", id: 7 },
        { value: "退款中", id: 8 },
        { value: "预授权成功", id: 11 },
        { value: "预授权资金冻结失败", id: 12 },
        { value: "预授权中", id: 13 },
        { value: "预授权解冻", id: 15 },
      ],

      pickerOptions: {
        // 设置不能超过未来时间
        // disabledDate: (time) => {
        //   // 设置可选择的日期为今天之后的一个月内
        //   const curDate = (new Date()).getTime()
        //   // 这里算出一个月的毫秒数,这里使用30的平均值,实际中应根据具体的每个月有多少天计算
        //   const day = 31 * 24 * 3600 * 1000
        //   const dateRegion = curDate - day
        //   return time.getTime() > Date.now() - 8.64e7 ||
        //   time.getTime() < dateRegion
        // }
        // 设置不能超过当天的23:59:59
        disabledDate(time) {
          let nowDate = new Date();
          let date = {
            year: nowDate.getFullYear(),
            month: nowDate.getMonth() + 1,
            date: nowDate.getDate(),
          };
          let timeDate =
            date.year + "-" + date.month + "-" + date.date + " 23:59:59";
          let times = new Date(timeDate).getTime();
          return time.getTime() > times;
        },
      },
    };
  },
  created() {
    this.userinfo = JSON.parse(sessionStorage.getItem("userInfo"));
    this.$store.dispatch("getNewNum", 6);
    // console.log(this.$store.state.changableNum);
    // console.log(this.$store.state.showFooter);
    // console.log(this.$store.state.logininfo);
    const start = new Date();
    start.setTime(start.getTime());
    const year = start.getFullYear();
    let month = start.getMonth() + 1;
    if (month < 10) {
      month = "0" + month;
    }
    let date = start.getDate();
    if (date < 10) {
      date = "0" + date;
    }
    const date1 = year + "-" + month + "-" + date + " 00:00:00";
    const date2 = year + "-" + month + "-" + date + " 23:59:59";
    this.date = [date1, date2];
    this.getPermissions();
    this.LedgerOrderQuery();
    // this.getservice('1')
    this.dictionarylist();
    // 根据角色区别模糊搜索内容
    if (this.userinfo.rolesId == 2 || this.userinfo.rolesId == 3) {
      getservice({
        type: 2,
        parentid: this.userinfo.fid,
      }).then((res) => {
        // console.log(res);
        for (var i = 0; i < res.data.rows.length; i++) {
          this.servicearr2.push({
            value: res.data.rows[i].agentname,
            id: res.data.rows[i].id,
          });
        }
      });
      this.getBD(this.userinfo.fid);
    } else if (this.userinfo.rolesId == 5) {
      this.conditions.merchantId = this.userinfo.fid;
    }
  },
  methods: {
      //复制官方订单号
    copyChannelTradeNoFunc(item){
      this.copyoutTradeNo = item.replace(/^\s+|\s+$/g, "");
    },
        onCopy: function (e) {
      this.$message({
        message: "复制成功",
        type: "success",
      });
      console.log("复制成功");
    },
    onError: function (e) {
      this.$message.error("复制失败");
      console.log("复制失败");
    },
    //分账
    InitiateAccountSplitting(val) {
      this.spFormVisible = true;
      this.tradeMerNo = val.tradeMerNo;
      this.tradeId = val.id;
    },
    //确认分账
    InitiateAccountOk() {
      APIDivideAccounts({
        tradeMerNo: this.tradeMerNo,
        tradeId: this.tradeId,
      }).then((res) => {
        this.spFormVisible = false;
        if (res.code == 200) {
           this.$message({
          message: '分账成功！',
          type: 'success'
        });
          this.LedgerOrderQuery();
        } else if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          this.$message.error(res.message);
        }
        // console.log("====", res);
      });
    },
    //详情弹窗
    JumpDetails(id) {
      sessionStorage.setItem("id", JSON.stringify(id));
      registeredEvents("Interactive_request");
      this.$router.push({ name: "SplitOrderDetails", params: { id } });
    },
    // 补录订单
    collectionOrder() {
      this.orderVisible = true;
    },
    // 补单页面关闭清空内容
    orderReset() {
      this.$refs.orderForm.resetFields();
      this.orderVisible = false;
    },
    // 获取所有通道type
    dictionarylist() {
      dictionarylist({ type: "channelType", status: 0,sort: "sorted", order:"DESC" }).then((res) => {
        // console.log(res);
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          this.channelslist = res.data;
          // console.log(this.channelslist);
        }
      });
    },
    //修改thead 背景色
    tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background-color: #F0F0F0;font-weight: 500;font-size:14px;color:#000;";
      }
    },
    // 刷新
    refresh() {
      this.$router.go({
        path: 0,
        query: {
          t: Date.now(),
        },
      });
    },
    // 获取商户列表初始化
    merchantslist(queryString, cb) {
      let sosolist = {};
      sosolist = {
        page: 1,
        size: 20,
        bdId: this.conditions.bdId,
        agent1Id: this.conditions.agent1Id,
        agent2Id: this.conditions.agent2Id,
        merchantName: this.conditions.merchantName,
      };
      merchantlist(sosolist).then((res) => {
        // console.log(res);
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          this.merchantarrlist = [];
          for (var i = 0; i < res.data.length; i++) {
            this.merchantarrlist.push({
              value: res.data[i].merchantName,
              id: res.data[i].id,
            });
          }
          let results = queryString
            ? this.merchantarrlist.filter(this.createFilter(queryString))
            : this.merchantarrlist;
          // 调用 callback 返回建议列表的数据
          cb(results);
        }
      });
    },
    // 选择商户
    okmerchants(val) {
      // console.log(val);
      this.conditions.merchantId = val.id;
    },
    // 获取门店列表初始化
    shoplist(queryString, cb) {
      shop({
        page: 1,
        size: 20,
        merchantId: this.conditions.merchantId,
        keywords: this.conditions.shopName,
      }).then((res) => {
        // console.log(res);
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          this.shoplists = [];
          for (var i = 0; i < res.data.length; i++) {
            this.shoplists.push({
              value: res.data[i].shopName,
              id: res.data[i].id,
            });
          }
          let results = queryString
            ? this.shoplists.filter(this.createFilter(queryString))
            : this.shoplists;
          // 调用 callback 返回建议列表的数据
          cb(results);
        }
      });
    },
    // 选择门店
    okshop(val) {
      // console.log(val)
      this.conditions.shopId = val.id;
      this.conditions.shopName = val.value;
    },
    //监听交易金额
    totalFeenum() {
      // console.log(this.conditions.totalFeenum)
      if (!this.conditions.totalFeenum) {
        this.conditions.totalFee = "";
      } else {
        this.conditions.totalFee = (
          this.conditions.totalFeenum * 100
        ).toFixed();
      }
    },
    //获取权限
    getPermissions() {
      let userInfoSessionStr = sessionStorage.getItem("userInfo");
      let userInfoSession = JSON.parse(userInfoSessionStr);
      this.myrolesId = userInfoSession.rolesId;
      if (
        this.myrolesId == 1 ||
        this.myrolesId == 2 ||
        this.myrolesId == 8 ||
        this.myrolesId == 5 ||
        this.myrolesId == 6
      ) {
        this.refundBtnFlag = true;
      } else if (this.myrolesId == 3) {
        if (userInfoSession.fid == 1309 || userInfoSession.fid == 889) {
          this.refundBtnFlag = true;
        } else {
          this.refundBtnFlag = false;
        }
      } else {
        this.refundBtnFlag = false;
      }
    },
    // 业务经理
    BDname(queryString, cb) {
      let BDarr = this.BDarr;
      let results = queryString
        ? BDarr.filter(this.createFilter(queryString))
        : BDarr;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    BDid(item) {
      //  console.log(item)
      this.conditions.bdId = item.id;
    },
    // 根据一级查2级
    serviceid(item) {
      this.servicearr2 = [];
      getservice({
        type: 2,
        parentid: item.id,
      }).then((res) => {
        // console.log(res);
        for (var i = 0; i < res.data.rows.length; i++) {
          this.servicearr2.push({
            value: res.data.rows[i].agentname,
            id: res.data.rows[i].id,
          });
        }
      });
      this.conditions.agent1Id = item.id;
      // console.log("this.conditions.agent1Id", this.conditions.agent1Id);
    },
    // 获取2级
    serviceid2(item) {
      this.conditions.agent2Id = item.id;
      this.conditions.BDname = "";
      // console.log(item);
      this.getBD(item.id);
    },
    getBD(id) {
      this.BDarr = [];
      getBD({ agentid: id }).then((res) => {
        // console.log(res);
        for (var i = 0; i < res.data.rows.length; i++) {
          this.BDarr.push({
            value: res.data.rows[i].name,
            id: res.data.rows[i].id,
          });
        }
      });
    },
    renderheader(h, { column, $index }) {
      return h("span", {}, [
        h("span", {}, column.label.split("?")[0]),
        h("br"),
        h("span", {}, column.label.split("?")[1]),
      ]);
    },
    // 分页导航
    handleCurrentChange(val) {
      this.cur_page = val;
      this.LedgerOrderQuery("1");
      this.$nextTick(() => {
        document.querySelectorAll(".content")[0].scrollTop = "0";
      });
    },
    // 分页数量
    sizechange(val) {
      this.cur_size = val;
      this.LedgerOrderQuery("1");

      this.$nextTick(() => {
        document.querySelectorAll(".content")[0].scrollTop = "0";
      });
    },
    //多选框
    handleSelectionChange(val) {
      // console.log(val);
      this.multipleSelection = val;
    },
    //  重置
    reset() {
      this.shopNo = "";
      this.shopName = "";
      this.payStatusCode = "";
      this.shopKeyWords = "";
      this.tradeNo = "";
      this.tradeKeyWords = "";
      this.splitFeeMch = "";
      this.shopCode = "";
      this.terminalNo = "";
      this.splitStatus = "";
      const start = new Date();
      start.setTime(start.getTime());
      const year = start.getFullYear();
      let month = start.getMonth() + 1;
      if (month < 10) {
        month = "0" + month;
      }
      let date = start.getDate();
      if (date < 10) {
        date = "0" + date;
      }
      const date1 = year + "-" + month + "-" + date + " 00:00:00";
      const date2 = year + "-" + month + "-" + date + " 23:59:59";
      this.date = [date1, date2];
      this.statistic = "123";
      this.conditions = {
        BDname: "",
        bdId: "",
        merchantId: "",
        payStatusCode: "",
      };
      this.cur_page = 1;
      if (this.userinfo.rolesId == 1 || this.userinfo.rolesId == 8) {
        this.servicearr2 = [];
        this.BDarr = [];
        this.merchantarrlist = [];
      } else if (this.userinfo.rolesId == 2) {
        this.BDarr = [];
        this.merchantarrlist = [];
      } else if (this.userinfo.rolesId == 5) {
        this.conditions.merchantId = this.userinfo.fid;
      }
    },
    // 搜索
    soso() {
      if (
        this.date == null ||
        this.date.length == 0 ||
        this.date == undefined
      ) {
        this.$message.error("查询时间不能为空");
        return;
      }
      this.cur_page = 1;
      // this.sosobtn = true;
      if (!this.conditions.agent1) {
        this.conditions.agent1Id = "";
      }
      if (!this.conditions.agent2) {
        this.conditions.agent2Id = "";
      }
      if (!this.conditions.BDname) {
        this.conditions.bdId = "";
      }
      if (!this.conditions.merchantName) {
        if (this.userinfo.rolesId != 5) {
          this.conditions.merchantId = "";
        }
      }
      if (!this.conditions.shopName) {
        this.conditions.shopId = "";
      }
      if (this.conditions.servicelevel == 1) {
        this.LedgerOrderQuery("1");
      } else if (this.conditions.servicelevel == 2) {
        this.LedgerOrderQuery("2");
      } else {
        this.LedgerOrderQuery("2");
      }
    },
    // 一级服务商
    querySearch(queryString, cb) {
      let sosolist = {};
      sosolist = {
        page: 1,
        size: 20,
        type: 1,
        keywords: this.conditions.agent1,
      };
      getservice(sosolist).then((res) => {
        // console.log(res);
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          this.servicearr1 = [];
          for (var i = 0; i < res.data.rows.length; i++) {
            this.servicearr1.push({
              value: res.data.rows[i].agentname,
              id: res.data.rows[i].id,
            });
          }
          let results = queryString
            ? this.servicearr1.filter(this.createFilter(queryString))
            : this.servicearr1;
          // 调用 callback 返回建议列表的数据
          cb(results);
        }
      });
    },
    // 二级服务商
    querySearch2(queryString, cb) {
      let servicearr = this.servicearr2;
      let sosolist = {};
      sosolist = {
        page: 1,
        size: 20,
        type: 2,
        keywords: this.conditions.agent2,
      };
      getservice(sosolist).then((res) => {
        // console.log(res);
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else {
          this.servicearr2 = [];
          for (var i = 0; i < res.data.rows.length; i++) {
            this.servicearr2.push({
              value: res.data.rows[i].agentname,
              id: res.data.rows[i].id,
            });
          }
          let results = queryString
            ? this.servicearr2.filter(this.createFilter(queryString))
            : this.servicearr2;
          // 调用 callback 返回建议列表的数据
          cb(results);
        }
      });
    },
    createFilter(queryString) {
      return (restaurant) => {
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) !==
          -1
        );
      };
    },
    // 获取一级服务商
    getservice(val) {
      getservice({
        type: val,
      }).then((res) => {
        // console.log(res);
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else if (res.code == 200) {
          for (var i = 0; i < res.data.rows.length; i++) {
            this.servicearr1.push({
              value: res.data.rows[i].agentname,
              id: res.data.rows[i].id,
            });
          }
        }
      });
    },
    //处理列表数据
    dealListDate(array) {
      for (let i = 0; i < array.length; i++) {
        array[i].trsSplitRate
          ? (array[i].trsSplitRate = array[i].trsSplitRate + "%")
          : (array[i].trsSplitRate = "-");
        if (!array[i].channelSplitNo) array[i].channelSplitNo = "-";
        if (!array[i].tradeNo) array[i].tradeNo = "-";
        if (!array[i].trsTotalFee) array[i].trsTotalFee = "-";
        if (!array[i].trsTradeFee) array[i].trsTradeFee = "-";
        if (!array[i].trsSplitFee) array[i].trsSplitFee = "-";
        if (!array[i].trsSplitFeePer) array[i].trsSplitFeePer = "-";
        if (!array[i].shopNo) array[i].shopNo = "-";
        if (!array[i].shopName) array[i].shopName = "-";
      }
      return array;
    },
    // 商户交易统计
    LedgerOrderQuery(level) {
      let sosolist = (sosolist = {
        page: this.cur_page,
        size: this.cur_size,
        tradeNo: this.tradeNo,
        startTime: this.date[0],
        finishTime: this.date[1],
        tradeKeyWords: this.tradeKeyWords,
        splitStatus: this.splitStatus,
        splitFeeMch: this.splitFeeMch,
        channelType: this.channelType,
        bdId: this.conditions.bdId,
        shopCode: this.shopCode,
        terminalNo: this.terminalNo,
        payStatusCode: this.payStatusCode,
        shopKeyWords: this.shopKeyWords,
        agent1Id: this.conditions.agent1Id,
        agent2Id: this.conditions.agent2Id,
      });
      // if (level == 1) {
      //   sosolist.agent1Id = this.conditions.serviceid;
      // } else if (level == 2) {
      //   sosolist.agent2Id = this.conditions.serviceid;
      // }
      //   }
      APILedgerOrderStatisticsQuery(sosolist).then((res) => {
        // console.log("统计", res);
        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else if (res.code == 200) {
          this.indentinfo = res.data;
        }
      });
      APILedgerOrderQuery(sosolist).then((res) => {
        // console.log("搜索条件", sosolist);

        if (res.code == 405) {
          sessionStorage.removeItem("token");
          this.$router.push("/login");
        } else if (res.code == 200) {
          let merdata = res.data;
          console.log("res.data444444=", merdata);

          this.merchantarr = this.dealListDate(merdata);
          console.log('this.merchantarr',this.merchantarr);

          // this.datainfo = res.data;
          this.combined = res.pageInfo.recordCount;
          this.pageCount = res.pageInfo.pageCount;
          this.loading = false;
        } else if (res.code == 500) {
          this.$message.error(res.message);
          this.loading = false;
        }
      });
    },
    //导出
    SplitOrderExcel() {
      this.eeeex = true;
      let i = 0;
      let time = setInterval(() => {
        if (i == 60) {
          loading.close();
          this.$message.error("请求超时");
          clearInterval(time);
        } else {
          i++;
        }
      }, 1000);
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      let level = this.conditions.servicelevel;
      let sosolist = (sosolist = {
        page: this.cur_page,
        size: this.cur_size,
        tradeNo: this.tradeNo,
        startTime: this.date[0],
        finishTime: this.date[1],
        tradeKeyWords: this.tradeKeyWords,
        splitStatus: this.splitStatus,
        splitFeeMch: this.splitFeeMch,
        channelType: this.channelType,
        bdId: this.conditions.bdId,
        shopCode: this.shopCode,
        terminalNo: this.terminalNo,
        payStatusCode: this.payStatusCode,
        shopKeyWords: this.shopKeyWords,
        agent1Id: this.conditions.agent1Id,
        agent2Id: this.conditions.agent2Id,
      });
      // if (level == 1) {
      //   sosolist.agent1Id = this.conditions.serviceid;
      // } else if (level == 2) {
      //   sosolist.agent2Id = this.conditions.serviceid;
      // }
      APISplitOrderExcel(sosolist).then((res) => {
        if (res.code == 405) {
          clearInterval(time);
          sessionStorage.removeItem("token");
          this.$router.push("/login");
          loading.close();
          this.exxxx = false;
        } else if (res.code == 200) {
          clearInterval(time);
          let elink = document.createElement("a");
          elink.download = "分账订单.xls";
          // elink.href = res.data;
          elink.href = res.data.replace("http://", "https://");
          elink.click();
          loading.close();
          this.exxxx = false;
        } else {
          clearInterval(time);
          this.$message.error(res.message);
          loading.close();
          this.exxxx = false;
        }
      });
    },
  },
};
</script>
<style scoped lang="less">
.iconmove{
  cursor:pointer;
}
.title {
  background: #fff;
  padding: 10px 10px;
  font-size: 18px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}
.name {
  width: 25%;
}
.screeningBox {
  width: 100%;
  display: flex;
}
.leftBox,
.rightBox {
  width: 50%;
  padding: 0 15px;
  box-sizing: border-box;
}
.leftBox > .leftitem {
  margin-bottom: 15px;
}
.rightBox > .rightitem {
  margin-bottom: 15px;
}
.merchants {
  width: 50%;
}
.tableBox {
  margin-top: 20px;
}
.servicename {
  width: 60%;
}
.servicelevel {
  width: 20%;
}
.width20 {
  width: 20%;
}
.width30 {
  width: 30%;
}
.red {
  color: #f9607d;
}
.stitle {
  padding: 5px 0;
  font-size: 18px;
}
.statistical {
  width: 100%;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: #00152a;
  color: #fff;
  padding: 12px;
  box-sizing: border-box;
}
.statistical > .statisticalitem {
  text-align: center;
  line-height: 200%;
}
.BDname {
  width: 20%;
}
.width60 {
  width: 40%;
}
.yuan {
  color: #c1c5cb;
  font-size: 12px;
  position: relative;
  left: -20px;
}
.green {
  background: #97c05c;
  color: #fff;
  padding: 0 5px;
  border-radius: 10px;
}
.orange {
  background: #f29c38;
  color: #fff;
  padding: 0 5px;
  border-radius: 10px;
}
.hui {
  background: #888888;
  color: #fff;
  padding: 0 5px;
  border-radius: 10px;
}
.reds {
  background: #d3362f;
  color: #fff;
  padding: 0 5px;
  border-radius: 10px;
}
.blue {
  background: #4154af !important;
  color: #fff;
  padding: 0 5px;
  border-radius: 10px;
}
.cyan {
  background: rgba(1, 255, 255) !important;
  color: #fff;
  padding: 0 5px;
  border-radius: 10px;
}
.yellow {
  background: #ffe793 !important;
  color: #000;
  padding: 0 5px;
  border-radius: 10px;
}
.notice-tip {
  color: red;
  font-size: 8px;
  text-align: center;
}
.el-divider--horizontal {
  margin: 0;
  margin-top: -20px;
  margin-bottom: 15px;
}
/deep/.el-input--small .el-input__inner {
  height: 32px;
  line-height: 32px;
}
.diver2th {
  margin-top: 15px;
}
.elForm {
  margin-left: 25px;
}
/deep/.dateTime .el-input--small .el-input__inner {
  width: 281px;
}
</style>